#include <cstdio>

int n, m;
bool f[ 235 ][ 235 ];

void init( )
{
    int i, j;
    for ( i = 0; i < n; i++ )
    {
        for ( j = 0; j < n; j++ )
            f[ i ][ j ] = false;
        f[ i ][ i ] = true;
    }
}

void work( )
{
    int i, j, k, u, v, cnt = 0;
    for ( i = 0; i < m; i++ )
    {
        scanf("%d%d", &u, &v);
        u--; v--;
        if ( f[ u ][ v ] )
            cnt++;
        else
            if ( !f[ v ][ u ] )
            {
                f[ v ][ u ] = true;
                for ( j = 0; j < n; j++ )
                {
                    if ( f[ u ][ j ] )
                    {
                        f[ v ][ j ] = true;
                        for ( k = 0; k < n; k++ )
                            if ( f[ k ][ v ] )
                                f[ k ][ j ] = true;
                    }
                }
            }
    }
    printf("%d\n", cnt);
}

int main( )
{
    int cas = 1;
    while ( scanf("%d%d", &n, &m) != EOF )
    {
        if ( n == 0 && m == 0 )
            break;
        printf("%d. ", cas++);
        init( );
        work( );
    }
    return 0;
}
